<template>
	<view>
		<view class="indexx">
			<image src="../../static/login.png" mode="" class="images"></image>
		</view>
		<button class="btns"  open-type="getPhoneNumber" @getphonenumber="getphonenumber">
			<view class="">
				微信手机号授权登录
			</view>
		</button>
	</view>
</template>

<script>
	import { getlogin } from '@/common/http.api.js';
	export default {
		data() {
			return {
				code:'',
				nicknames:'',
				avastars:'',
				genders:'',
			};
		},
		onLoad() {
		},
		methods: {
			getphonenumber(e) {
				let that = this
				that.code = e.detail.code
				uni.getUserInfo({
				      provider: 'weixin',
				      success: function (infoRes) {
						that.nicknames = infoRes.userInfo.nickName
						that.avastars = infoRes.userInfo.avatarUrl
						that.log()
				      }
				});
			},
			log(){
				let that = this
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
					  let params = {
						  phoneCode:that.code,
						  code:loginRes.code,
						  nickName:that.nicknames,
						  headImg:that.avastars,
					  }
					  getlogin(params).then(res=>{
						  if(res.code == 200){
							  uni.setStorageSync('token',res.token)
							  uni.navigateBack()
						  }else{
							  uni.showToast({
							  	icon:'error',
								title:'登录失败'
							  })
						  }
						 
						  // uni.switchTab({
						  // 	url:'/pages/my/my'
						  // })
					  })
				  }
				});
			},
		},
	}
</script>

<style lang="scss">
page{
	background-color: #ffffff;
}
.indexx{
	margin: 240rpx auto;
	width: 100%;
	display: flex;
	justify-content: center;
}
.images{
	width: 180rpx;
	height: 180rpx;
	border-radius: 50%;
}
.btns{
	background-color: #022B5F;
	border-radius: 40rpx;
	width: 548rpx;
	height: 80rpx;
	color: #FFFFFF;
	font-weight: bold;
	font-size: 32rpx;
}

</style>
